//
//  DYPhotoHeaderCollectionViewCell.m
//  PrivatePhoto
//
//  Created by PrivatePhoto Team on 2021.
//  Copyright © 2021年 PrivatePhoto Team. All rights reserved.
//

#import "DYPhotoHeaderCollectionViewCell.h"

@implementation DYPhotoHeaderCollectionViewCell

- (void)awakeFromNib {
    // Initialization code
    [super awakeFromNib];
}

- (void)setData:(id)data delegate:(id)delegate {

    _delegate = delegate;
    
    if ([data isKindOfClass:[NSDictionary class]]) {
        if ([data[@"data"] isKindOfClass:[CAPhotoHeaderCollectionViewCellModel class]]) {
            CAPhotoHeaderCollectionViewCellModel *model = data[@"data"];
            _model = model;
            
            _titleLabel.text = [NSString stringWithFormat:@"%ld张照片",model.count];

            if (model.isSelect) {
                [_selectButton setTitle:@"取消选中" forState:UIControlStateNormal];
            } else {
                [_selectButton setTitle:@"全选" forState:UIControlStateNormal];
            }

        }
    }
}

- (IBAction)buttonAction:(UIButton *)sender {
    if (_delegate && [_delegate respondsToSelector:@selector(photoHeaderCollectionViewCell:buttonAction:)]) {
        [_delegate photoHeaderCollectionViewCell:self buttonAction:sender];
    }
}

@end




#pragma mark - Model

@implementation CAPhotoHeaderCollectionViewCellModel

+ (CAPhotoHeaderCollectionViewCellModel *)ittemModelWithCount:(NSInteger)count isSelect:(BOOL)isSelect section:(NSInteger)section {
    CAPhotoHeaderCollectionViewCellModel *model = [CAPhotoHeaderCollectionViewCellModel new];
    model.count = count;
    model.isSelect = isSelect;
    model.section = section;
    return model;
}

@end
